package fr.perso.ppo.springintegration.business;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.Message;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.stereotype.Component;

import fr.perso.ppo.springintegration.domain.PaiementGDPA;

@Component("businessStep2Service")
public class BusinessStep2Service {
	
	private static Logger log = LoggerFactory.getLogger(BusinessStep2Service.class);
	
	private static String headerName="backDeGestionHeader";

	public Message<?> route(PaiementGDPA paiement) throws Exception {
		// TODO CAS ERREUR
		log.warn("------Business STEP2 sur paiement (id:{})", paiement.getId());
		log.warn("------Ajout HEADER ROUTAGE ------Business STEP2 sur paiement (id:{})", paiement.getId());
		
		Message<PaiementGDPA> msg = null;
		String headerValue = null;
		//TODO nom des back dans un enum
		
		headerValue = ((paiement.getId() % 2)==0?"TIGRE":"GB2000");
		 
		msg = MessageBuilder.withPayload(paiement).setHeader(headerName, headerValue).build();
		
		
		return msg;
	}

}
